package org.zjx.analysis.analyze.charm;

import org.zjx.analysis.analyze.window.AbstractWindowAnalyzer;
import org.zjx.command.entity.screen.Address;
import org.zjx.command.util.ImageUtil;
import org.zjx.window.window.IWindow;

import java.awt.*;
import java.awt.image.BufferedImage;

public class FlyingCharmAnalysis extends AbstractWindowAnalyzer {

    public FlyingCharmAnalysis(IWindow window, BufferedImage screenshot) {
        super("飞行符", "飞行符", window);
    }

    public static Address targetAddress(String cityName) {
        switch (cityName) {
            case "长寿村":
                return new Address("长寿村", 111, 61);
            case "西梁女国":
                return new Address("西梁女国", 101, 28);
            case "宝象国":
                return new Address("西梁女国", 115, 70);
            case "朱紫国":
                return new Address("朱紫国", 140, 93);
            case "长安城":
                return new Address("长安城", 361, 243);
            case "建邺城":
                return new Address("建邺城", 65, 30);
            case "傲来国":
                return new Address("傲来国", 123, 94);
            default:
                throw new IllegalArgumentException("飞行符城市不存在：" + cityName);
        }
    }

    @Override
    protected void initResources() {

    }

    public Rectangle getCityLocation(String cityName) {
        Rectangle rectangle = areaMap.get(cityName).getRectangle();
        return conversion(windowArea, rectangle);
    }

    @Override
    public Rectangle closeArea() {
        return ImageUtil.createRect(615, 2, 630, 17);
    }

    @Override
    public Rectangle getOriginBounds() {
        return ImageUtil.createRect(83, 147, 715, 450);
    }

    @Override
    public Rectangle getRefImageArea() {
        return ImageUtil.createRect(14, 13, 30, 30);
    }

    @Override
    public BufferedImage getRefImage() {
        return ImageUtil.createImage("iVBORw0KGgoAAAANSUhEUgAAABEAAAASCAYAAAC9+TVUAAAAn0lEQVR4XqXQIRqAIAyAUe9/Io9ANBgIhgWDwbBgR2EgOJiAhhU+fP5sUPNoplUZvWk2UB21aDdDBPJLtbkRBf8Ah/ytSJAAtYMMyS+0YIUSDvAzGaggMtaJgIF9onMsA8JOImKBRkQuuZEL2N4RXkKQA5B+YIFOJKn4jvgSJOgzEio6EL5YIMA/5YEIULEEj7iPFJFqMsR+XELwiAiHTvjRSrt23vHeAAAAAElFTkSuQmCC");

    }

    @Override
    public void analyze(BufferedImage image) {
        areaMap.put("长寿村", new ResolutionArea(ImageUtil.createRect(207, 21, 229, 52)));
        areaMap.put("西梁女国", new ResolutionArea(ImageUtil.createRect(202, 87, 225, 111)));
        areaMap.put("宝象国", new ResolutionArea(ImageUtil.createRect(188, 169, 219, 193)));
        areaMap.put("朱紫国", new ResolutionArea(ImageUtil.createRect(254, 234, 278, 261)));
        areaMap.put("长安城", new ResolutionArea(ImageUtil.createRect(383, 101, 469, 162)));
        areaMap.put("建邺城", new ResolutionArea(ImageUtil.createRect(426, 201, 461, 222)));
        areaMap.put("傲来国", new ResolutionArea(ImageUtil.createRect(578, 255, 614, 284)));
    }
}
